" https://github.com/rafi/vim-config
" Created By: Rafael Bodill

" Runtime and Plugins
" ===

if &compatible
	" vint: -ProhibitSetNoCompatible
	set nocompatible
	" vint: +ProhibitSetNoCompatible
endif

" Set main configuration directory as parent directory
let $VIM_PATH = fnamemodify(resolve(expand('<sfile>:p')), ':h:h')

function! s:source_file(path, ...)
	" Source user configuration files with set/global sensitivity
	let use_global = get(a:000, 0, ! has('vim_starting'))
	let abspath = resolve($VIM_PATH . '/' . a:path)
	if ! use_global
		execute 'source' fnameescape(abspath)
		return
	endif

	let tempfile = tempname()
	let content = map(readfile(abspath),
		\ "substitute(v:val, '^\\W*\\zsset\\ze\\W', 'setglobal', '')")
	try
		call writefile(content, tempfile)
		execute printf('source %s', fnameescape(tempfile))
	finally
		if filereadable(tempfile)
			call delete(tempfile)
		endif
	endtry
endfunction

" Initialize startup settings
if has('vim_starting')
	" Use spacebar as leader and ; as secondary-leader
	" Required before loading plugins!
	" let g:mapleader="\<Space>"
	let g:mapleader=","
	let g:maplocalleader=';'

	" Release keymappings prefixes, evict entirely for use of plug-ins.
	nnoremap <Space>  <Nop>
	xnoremap <Space>  <Nop>
	nnoremap ,        <Nop>
	xnoremap ,        <Nop>
	nnoremap ;        <Nop>
	xnoremap ;        <Nop>

	" Vim only, Linux terminal settings
	if ! has('nvim') && ! has('gui_running') && ! has('win32') && ! has('win64')
		call s:source_file('config/terminal.vim')
	endif
endif

" Load user scripts with confidential information
" or pre-settings like g:elite_mode
if filereadable($VIM_PATH . '/.vault.vim')
	call s:source_file('.vault.vim')
endif

" Initialize plugin-manager and load main config files
call s:source_file('config/init.vim')
call s:source_file('config/plugins/all.vim')

" Initialize all my configurations
call s:source_file('config/general.vim')
call s:source_file('config/filetype.vim')
call s:source_file('config/mappings.vim')
" call s:source_file('config/theme.vim')
colorscheme hybrid_reverse  " change to your favorite theme

" Load user custom local settings
if filereadable($VIM_PATH . '/config/local.vim')
	call s:source_file('config/local.vim')
endif

if get(g:, 'statusline_plugin_enable', 1)
	call s:source_file('config/statusline.vim')
endif
if get(g:, 'tabline_plugin_enable', 1)
	call s:source_file('config/tabline.vim')
endif

set secure

" vim: set ts=2 sw=2 tw=80 noet :
